<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <title>我的会诊</title>
    <script src="js/rem.js"></script>
    <link rel="stylesheet" href="css/weui.min.css">
    <link rel="stylesheet" href="css/jquery-weui.min.css">
    <link rel="stylesheet" href="css/public.css">
    <link rel="stylesheet" href="css/user.css">
    <script>(function() {var _53code = document.createElement("script");_53code.src = "https://tb.53kf.com/code/code/96d8f960b261e49515450f8953b044bc5/1";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_53code, s);})();</script>
</head>
<body>
    <!-- 普通用户列表 -->
    <div class="pub-container user-consultation bgwhite">
        <div class="top-notice">咨询过的会诊在这里查看</div>
        <div class="main">
            <ul class="tabs space-border" id="ctab">
                <li class="active">会诊咨询</li>
                <li>我的病历</li>
                <li>待会诊</li>
                <li>会诊结果</li>
                <li>退款</li>
            </ul>
            <ul class="c-list" id="clist">
                <li class="active" id="list1">
                </li>
                <li id="list2">
                </li>
                <li id="list3">
                </li>
                <li id="list4">
                </li>
                <li id="list5">
                </li>
            </ul>
        </div>
        <!-- 取消预约弹窗 -->
        <div class="cancel popup">
            <div class="cont plr15">
                <ul>
                    <li data-type='1'>修改会诊时间</li>
                    <li data-type='2'>取消会诊</li>
                </ul>
                <div class="btns">
                    <a class="cancel" href="javascript:;">取消</a>
                    <a class="confirm" href="javascript:;">确定</a>
                </div>
            </div>
        </div>
        <!--跳转小程序弹窗 -->
        <div class="weapp-popup">
            <div class="cont plr15">
                <wx-open-launch-weapp id="launch-btn" username="gh_3baf85f7018e" path="/pages/index/index" class="weapp-btn" >
                    <template> 
                        <style>
                            .btn {
                                text-align: center;
                                outline: none;
                                border: none;
                                background-color: transparent;
                                margin: 0;
                                width: 100vw;
                                height: 40px;
                                line-height: 40px;
                                vertical-align: middle;
                            }
                            .btn:focus{outline: none;}
                        </style>
                        <button class="btn">跳转小程序</button>
                    </template>
                </wx-open-launch-weapp>
            </div>
        </div>
    </div>
    <script src="js/jweixin-1.6.0.js"></script>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/jquery-weui.min.js"></script>
    <script src="js/md5.js"></script>
    <script src="js/public.js"></script>
    <script>
        xcxConfig();
        $('#list4').on('click', '.consultation-info', function(e){
            location.href = "user-consul-detail.html?type=2&specialistId=" + $(e.currentTarget).attr('data-specialistId');
        })
        // tabs切换
        $('#ctab li').click(function(){
            var $this= $(this);
            $this.addClass('active').siblings().removeClass('active');
            $('#clist > li').removeClass('active').eq($this.index()).addClass('active');
            // $('#list3 .toWeapp').each(function(index,item){
            //     $(item).html('开始会诊' + getWeappHtml($(item).attr('data-address')));
            // });
            [getList1, getList2,getList3,getList4,getList5][$this.index()]();
        })

        // 获取列表
        getList1();
        // getList2();
        // getList3();
        // getList4();
        // getList5();

        // 获取普通用户列表 - 会诊咨询
        function getList1(){
            http('/consulation/queryConsultByUser', {
                hasToken: true,
                success: function(res){
                    if(res.code === '01'){
                        var data = res.data, html = '';
                        data.forEach(function(item, index){
                            html += '<div class="consultation-info space-border plr15" data-id="' + item.specialistId + '">' + 
                                '<div class="user-box box1">' + 
                                    '<p class="consultation-time">咨询时间<span>' + format(item.consultTime) + '</span></p>' + 
                                    '<a class="custom-btn" href="' + customUrl + '">咨询客服</a>' + 
                                '</div>' + 
                                '<div class="user-box box2">' + 
                                    '患者姓名:<span>' + item.patientName + '</span>' + 
                                    '性别:<span>' + SEXDINC[item.patientSex] + '</span>' + 
                                    '年龄:<span>' + item.patientAge + '</span>' + 
                                '</div>' + 
                                '<div class="user-box box3">' + 
                                    '<p class="title">会诊目的</p>' + 
                                    '<p class="purpose">' + item.consultMessage +'</p>' + 
                                '</div>' + 
                            '</div>';
                        })
                        html += getNoDataHtml();
                        $('#list1').html(html);
                    }
                }
            });
        }

        // 获取普通用户列表 - 我的病历
        function getList2(){
            http('/consulation/queryBasic', {
                hasToken: true,
                success: function(res){
                    if(res.code === '01'){
                        var data = res.data, html = '';
                        data.forEach(function(item, index){
                            html += '<div class="consultation-info space-border plr15">' + 
                                '<div class="user-box box1">' + 
                                    '<p class="consultation-time">咨询时间<span>' + format(item.consultTime) + '</span></p>' + 
                                    '<a class="custom-btn" href="' + customUrl + '">咨询客服</a>' + 
                                '</div>';
                                if(item.doctors){
                                    html += '<div class="user-box box2">' + 
                                        '申请科室:<span>' + item.doctors[0].departmentCode + '</span>' + 
                                        '申请医生:<span>' + item.doctors[0].userName + '</span>' + 
                                    '</div>';
                                }
                                html += '<div class="user-box box3">' + 
                                    '<p class="title">会诊目的</p>' + 
                                    '<p class="purpose">' + item.treamentMessage +'</p>' + 
                                '</div>' + 
                                '<div class="user-box box4">' + 
                                    '<ul class="see-list">' + 
                                        '<li>' + 
                                            '<p class="last-text-justify">诊 断</p>' + 
                                            '<p class="txt2">' + item.diagnose + '</p>' + 
                                        '</li>' + 
                                        '<li>' + 
                                            '<p class="last-text-justify">主 诉</p>' + 
                                            '<p class="txt2">' + item.complain + '</p>' + 
                                        '</li>' + 
                                    '</ul>' + 
                                    '<div class="btn-wrapper">' + 
                                        '<a class="pub-bth" href="user-consul-detail.html?type=1&specialistId=' + item.specialistId + '">查看病例</a>' + 
                                    '</div>' + 
                                '</div>' + 
                            '</div>';
                        })
                        html += getNoDataHtml();
                        $('#list2').html(html);
                    }
                }
            });
        }

        // 获取普通用户列表 - 待会诊
        function getList3(){
            http('/consulation/queryMessageByUserId', {
                hasToken: true,
                success: function(res){
                    if(res.code === '01'){
                        var data = res.data, html = '';

                        data.forEach(function(item, index){
                            var type = item.type; //就诊方式
                            html += '<div class="consultation-info space-border">' + 
                                '<div class="user-box box1 plr15 bb0">' + 
                                    '<p class="consultation-time">咨询时间<span>' + format(item.consultTime) + '</span></p>' + 
                                    '<a class="custom-btn" href="' + customUrl + '">咨询客服</a>' + 
                                '</div>' + 
                                '<div class="user-box box3 plr15">' + 
                                    '<div class="sq-info">' + 
                                        '<p><span class="txt1">会诊时间:</span><span>' + format(item.consulationTime) + '</span></p>' + 
                                        '<p><span class="txt1">会诊专家:</span><span>' + item.consulationSpecialist + '</span></p>' + 
                                        '<p><span class="txt1">会诊科室:</span><span>' + item.consulationDepartment + '</span></p>' + 
                                        '<p><span class="txt1">会诊方式:</span><span>' + CONSUTATIONTYPE[type] + '</span></p>';
                            if(type == 0){
                                html += '<p><span class="txt1">会诊地址:</span><span>' + item.consulationAddress + '</span></p>';
                            }      
                            html += '</div>' + 
                                    '<div class="money-box plr15">' + 
                                        '<p class="txt1">会诊费</p>' + 
                                        '<p><span class="money">' + item.consulationMoney + '</span><span class="unit">元</span></p>' + 
                                    '</div>' + 
                                '</div>' + 
                                '<div class="user-box box3">';
                            // 订单生效状态为生效
                            if(item.effectType == 1){
                                // 订单状态为30分钟倒计时
                                if(item.orderStatus == '03'){
                                    html += '<div class="status-box plr15">' + 
                                                '<p class="status">待支付</p>' + 
                                                '<a class="pay-btn toPay" href="pay.html?orderId=' + item.orderId + '&orderNo=' + item.orderNo + '&consulationTime=' + format(item.consulationTime) + '&consulationSpecialist=' + encodeURIComponent(item.consulationSpecialist) + '&consulationDepartment=' + encodeURIComponent(item.consulationDepartment) + '&type=' +  encodeURIComponent(CONSUTATIONTYPE[type]) + '&money=' + encodeURIComponent(item.consulationMoney) + '&time=' +  encodeURIComponent(item.orderTime) + '">支付会诊费</a>' + 
                                            '</div>';
                                }else if(item.orderStatus == '04'){
                                    html += '<div class="status-box plr15">' + 
                                        '<p class="status">已支付</p>' + 
                                        '<div>' + 
                                            '<a class="pay-btn btn2 mr1" data-specialistId="' + item.specialistId + '" data-orderNo="' + item.orderNo + '"  data-orderId="' + item.orderId + '" href="javascript:;">取消会诊</a>';
                                            if(type == 1){
                                                html += '<div class="pay-btn toWeapp" data-address="' + item.consulationAddress + '">开始会诊</div>';
                                            }
                                    html += '</div>' + 
                                    '</div>';
                                }
                            }else {
                                html += '<div class="status-box plr15">' + 
                                    '<p class="status">已失效</p>' +
                                '</div>';
                            }
                            html += '<div class="pay-tip plr15">' + 
                                        '<p>*注：1.您可以在会诊开始3天内之前随时取消会诊进行退款，会诊 费会在7天内退回您的支付账户；</p>' + 
                                        '<p>2.会诊开始前，3天内不予退款，敬请谅解；</p>' + 
                                        '<p>3.此订单支付的有效时间为30分钟，请在在30分钟内支付此订单；</p>' + 
                                    '</div>' + 
                                '</div>' + 
                        ' </div>';
                        })
                        html += getNoDataHtml();
                        $('#list3').html(html);
                        $('#list3 .toWeapp').each(function(index,item){
                            $(item).html('开始会诊' + getWeappHtml($(item).attr('data-address')));
                        });
                    }else {
                        $('#list3').html(getNoDataHtml());
                    }
                }
            })
        }
    
        // 获取普通用户列表 - 会诊结果
        function getList4(){
            http('/consulation/queryResultByUser', {
                hasToken: true,
                success: function(res){
                    if(res.code === '01'){
                        var data = res.data, html = '';

                        data.forEach(function(item, index){
                            var type = item.consulationType; //就诊方式
                            html += '<div class="consultation-info space-border" data-specialistId="' + item.specialistId + '">' + 
                                '<div class="user-box box1 plr15 bb0">' + 
                                    '<h4 class="user-pub-tit">会诊信息</h4>' + 
                                    '<a class="custom-btn" href="' + customUrl + '">咨询客服</a>' + 
                                '</div>' + 
                                '<div class="user-box box3 plr15">' + 
                                    '<ul class="see-list">' + 
                                        '<li>' + 
                                            '<p class="last-text-justify">会诊时间</p>' + 
                                            '<p class="txt2">' + format(item.consulationTime) + '</p>' + 
                                        '</li>' + 
                                        '<li>' + 
                                            '<p class="last-text-justify">会诊专家</p>' + 
                                            '<p class="txt2">' + item.consulationSpecialist + '</p>' + 
                                        '</li>' + 
                                        '<li>' + 
                                            '<p class="last-text-justify">会诊方式</p>' + 
                                            '<p class="txt2">' + ((type === '' || type == null) ? '' : CONSUTATIONTYPE[type]) + '</p>' + 
                                        '</li>' + 
                                        '<li>' + 
                                            '<p class="last-text-justify">会诊科室</p>' + 
                                            '<p class="txt2">' + item.consulationDepartment + '</p>' + 
                                        '</li>' + 
                                        '<li>' + 
                                            '<p class="last-text-justify">会诊地址</p>' + 
                                            '<p class="txt2">' + item.consulationDepartment + '</p>' + 
                                        '</li>' + 
                                    '</ul>' + 
                                    '<p class="title">会诊意见</p>' + 
                                    '<p class="purpose">' + item.adviceMessage + '</p>' + 
                                '</div>' + 
                            '</div>';
                        })
                        html += getNoDataHtml();
                        $('#list4').html(html);
                    }
                }
            })
       
        }

        // 获取普通用户列表 - 退款
        function getList5(){
            http('/consulation/getRefundList', {
                hasToken: false,
                data: {
                    userId: getCookie('userId')
                },
                success: function(res){
                    if(res.code === '01'){
                        var data = res.data, html = '';
                        console.log(data)
                        data.forEach(function(item, index){
                            var doctor = item.doctors ? item.doctors[0] : null
                            html += '<div class="consultation-info space-border plr15">' + 
                                '<div class="user-box box1">' + 
                                    '<p class="consultation-time">申请时间<span>' + format(item.timeStamp) + '</span></p>' + 
                                    '<a class="custom-btn" href="' + customUrl + '">咨询客服</a>' + 
                                '</div>';
                                if(doctor){
                                    html += '<div class="user-box box2">' + 
                                        '申请科室:<span>' + doctor.departmentCode + '</span>' + 
                                        '申请医生:<span>' + doctor.userName + '</span>' + 
                                    '</div>';
                                }
                                
                            html += '<div class="user-box box3">' + 
                                    '<p class="title">会诊目的</p>' + 
                                    '<p class="purpose">' + item.treamentMessage + '</p>' + 
                                    '<div class="status-box2 plr15">' + 
                                        '<div class="money-box">' + 
                                            '<p class="txt1">会诊费</p>' + 
                                            '<p><span class="money">' + item.money + '</span><span class="unit">元</span></p>' + 
                                        '</div>';
                                    if(item.refundStatus === '1'){
                                        html += '<p class="status">待退款</p>'
                                    }else if(item.refundStatus === '2') {
                                        html += '<p class="status">已退款</p>'
                                    }
                            html += '</div>' + 
                                '</div>' + 
                            '</div>';
                        })
                        html += getNoDataHtml();
                        $('#list5').html(html);
                    }
                }
            })
        }
        
        // 取消会诊
        var specialistId, orderNo, orderId;
        $(document.body).on('click', '.pay-btn.btn2', function(e){
            $btn = $(this);
            specialistId = $btn.attr('data-specialistId');
            orderNo = $btn.attr('data-orderNo');
            orderId = $btn.attr('data-orderId');
            $('.cancel.popup').show();
        })
        $('.cancel.popup .cancel').click(function(e){
            e.stopPropagation();
            specialistId = '';
            orderNo = '';
            orderId = '';
            $('.cancel.popup li').removeClass('active');
            $('.cancel.popup').hide();
        })
        $('.cancel.popup .confirm').click(function(e){
            e.stopPropagation();
            
            var type = $('.cancel.popup li.active').attr('data-type');
            if(validEmpty(type, '请选择取消会诊方式')) return false;
            http('/consulation/cancelConsulation', {
                hasToken: false,
                data: {
                    type: type,
                    specialistId: specialistId,
                    orderNo: orderNo,
                    orderId: orderId
                },
                success: function(res){
                    if(res.code === '01'){
                        specialistId = '';
                        orderNo = '';
                        $('.cancel.popup li').removeClass('active');
                        toast('取消会诊成功');
                        $('.cancel.popup').hide();
                        setTimeout(getList3, 1500)
                    }
                }
            })
        })
        $('.cancel.popup li').click(function(e){
            e.stopPropagation();
            $(this).addClass('active').siblings().removeClass('active');
        })
    </script>
</body>
</html>